package parser

import (
	"regexp"
	"spider/engine"
)

var (
	Recity    = regexp.MustCompile(`<a href="(http://album.zhenai.com/u/[0-9]+)"[^>]*>([^<]+)</a>`)
	RecityUrl = regexp.MustCompile(`(http://www.zhenai.com/zhenghun/[^"]+)`)
)

func ParserCity(contents []byte) engine.ParseResult {

	matches := Recity.FindAllSubmatch(contents, -1)

	result := engine.ParseResult{}
	for _, m := range matches {
		url := string(m[1])
		name := string(m[2])
		result.Requests = append(result.Requests, engine.Request{
			Url: url,
			ParserFunc: func(contents []byte) engine.ParseResult {
				return ParserProfile(contents, url, name)
			},
		})
	}

	matches = RecityUrl.FindAllSubmatch(contents, -1)
	for _, m := range matches {
		result.Requests = append(result.Requests, engine.Request{
			Url:        string(m[0]),
			ParserFunc: ParserCity,
		})
	}

	return result
}
